package com.company.creational.singleton_pattern.lazy;

/**
 * @ClassName LazySingleton2
 * @Author tiezheng.han
 * @Date 2020/8/28 9:42
 **/
public class LazySingleton2 {

    private static LazySingleton2 instance = null;

    private LazySingleton2(){}

    /**
     * 使用synchronize关键字对方法加锁，确保任意时刻只有一个线程可执行该方法
     */

    public static LazySingleton2 getInstance(){
        if (instance == null){
            synchronized (LazySingleton2.class){
                instance = new LazySingleton2();
            }
        }
        return instance;
    }
}
